<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" href="css/bootstrap.min.css" />
	</head>

	<body>
		<div class="container">
			<!-- 首页 -->
			<div class="row text-center" style="margin-top: 100px;">
				<img src="img/logo.png" style="height: 200px; margin-bottom:30px; "/>
				<div class="input-group col-xs-8 col-xs-offset-2">
					<input id="searchText" type="text" class="form-control" placeholder="搜索关键字，关键字请用空格分开" onkeypress="if(event.keyCode == 13) EsSearch();">
					<span class="input-group-btn">
						<button class="btn btn-primary" style="width: 100px;" onclick="EsSearch();">搜索一下</button>
					</span>
				</div>
			</div>
			<div class='text-center'>
				<h4>热门搜索</h4>
				<div style="font-size:12px;color: grey;">
					<button type="button" class="btn btn-default btn-xs" onclick="QuickSearch('游戏')">游戏</button>
					<button type="button" class="btn btn-default btn-xs" onclick="QuickSearch('编程')">编程</button>
					<button type="button" class="btn btn-default btn-xs" onclick="QuickSearch('代码')">代码</button>
					<button type="button" class="btn btn-default btn-xs" onclick="QuickSearch('软件')">软件</button>
					<button type="button" class="btn btn-default btn-xs" onclick="QuickSearch('产品')">产品</button>
					<button type="button" class="btn btn-default btn-xs" onclick="QuickSearch('设计')">设计</button>
					<button type="button" class="btn btn-default btn-xs" onclick="QuickSearch('学习')">学习</button>
					<button type="button" class="btn btn-default btn-xs" onclick="QuickSearch('iOS')">iOS</button>
					<button type="button" class="btn btn-default btn-xs" onclick="QuickSearch('Android')">Android</button>
					<br/>
					<button type="button" class="btn btn-default btn-xs" onclick="QuickSearch('互联网')">互联网</button>
					<button type="button" class="btn btn-default btn-xs" onclick="QuickSearch('程序员')">程序员</button>
					<button type="button" class="btn btn-default btn-xs" onclick="QuickSearch('计算机')">计算机</button>
					<button type="button" class="btn btn-default btn-xs" onclick="QuickSearch('前端开发')">前端开发</button>
					<button type="button" class="btn btn-default btn-xs" onclick="QuickSearch('游戏开发')">游戏开发</button>
					<button type="button" class="btn btn-default btn-xs" onclick="QuickSearch('移动互联网')">移动互联网</button>
					<br/>
				</div>
			</div>
			<!-- 搜索结果 -->
			<div class="row" style="margin-top: 20px;">
				<div class="col-xs-10 col-xs-offset-1">
					<div class="list-group">
						<!-- <div class="list-group-item" style="border: 0;">
							<a href="#" style="color: #0F0F0F;"><h4>1.神秘客</h4></a>
							<p>
								<span class="badge">关键字</span>
								<span class="badge">关键字</span>
								<span class="badge">关键字</span>
							</p>
						</div>
						<div style="border: 1px dashed #ddd;"></div>
						
						<div class="list-group-item" style="border: 0;">
							<a href="#" style="color: #0F0F0F;"><h4>2.神秘客</h4></a>
							<p>
								<span class="badge">关键字</span>
								<span class="badge">关键字</span>
								<span class="badge">关键字</span>
							</p>
						</div> 
						<div style="border: 1px dashed #ddd;"></div>-->
					</div>
				</div>
			</div>
		</div>
		<!-- <script type="text/javascript" src="js/jquery-1.11.3.min.js"></script> -->
		<script src="//cdn.bootcss.com/jquery/1.12.0/jquery.min.js"></script>
		<script type="text/javascript" src="js/bootstrap.min.js"></script>
		<script type="text/javascript">
			function EsSearch(){
				var searchText = $("#searchText").val();
				//alert(searchText);
				$.ajax({
					url : "/searchEngine-web/getIndexByKeyWords",
					type : "POST",
					data : {"keyWords":searchText},
					success : function(data) {
						if("未搜索到任何结果" == data){
							$(".list-group").html("<div class='text-center'><h4>未搜索到任何结果</h4></div>");
						}else{
							var urls = [];
							var pageNames = [];
							var result = JSON.parse(data);
							if(result == 0){
								$(".list-group").html("<div class='text-center'><h4>未搜索到任何结果</h4></div>");
							}else{
								for(var i=0;i<result.length;i++){
									urls[i] = result[i].url;
									pageNames[i] = result[i].pageName;
								}
								//拼显示的html代码
								var listHtml = "<div class='text-center'><h4>搜索到以下结果</h4></div>";
								for(var i=0; i<result.length; i++){
									listHtml += "<div class='list-group-item' style='border: 0;'>"+
													"<a href='"+ urls[i] +"' style='color: #0F0F0F;' target='_blank'><h4>"+ (i+1) + "." + pageNames[i] +"</h4></a>"+
												"</div>"+
												"<div style='border: 1px dashed #ddd;'></div>";
								}
								$(".list-group").html(listHtml);
							}
						}
					}
				});
			}
			function QuickSearch(searchText){
				$("#searchText").val(searchText);
				//alert(searchText);
				$.ajax({
					url : "/searchEngine-web/getIndexByKeyWords",
					type : "POST",
					data : {"keyWords":searchText},
					success : function(data) {
						if("未搜索到任何结果" == data){
							$(".list-group").html("<div class='text-center'><h4>未搜索到任何结果</h4></div>");
						}else{
							var urls = [];
							var pageNames = [];
							var result = JSON.parse(data);
							if(result == 0){
								$(".list-group").html("<div class='text-center'><h4>未搜索到任何结果</h4></div>");
							}else{
								for(var i=0;i<result.length;i++){
									urls[i] = result[i].url;
									pageNames[i] = result[i].pageName;
								}
								//拼显示的html代码
								var listHtml = "<div class='text-center'><h4>搜索到以下结果</h4></div>";
								for(var i=0; i<result.length; i++){
									listHtml += "<div class='list-group-item' style='border: 0;'>"+
													"<a href='"+ urls[i] +"' style='color: #0F0F0F;' target='_blank'><h4>"+ (i+1) + "." + pageNames[i] +"</h4></a>"+
												"</div>"+
												"<div style='border: 1px dashed #ddd;'></div>";
								}
								$(".list-group").html(listHtml);
							}
						}
					}
				});
			}
		</script>
	</body>

</html>